import { defineStore } from "pinia"
import { computed, ref } from "vue"

export const useCounterStore = defineStore('counter', () => {

  // 1. 定义数据
  const count = ref(100)
  const doubleCount = computed(()=>{
    return count.value * 2
  })

  const num1 = ref(100)
  const num2 = ref(200)

  // 2. 定义操作数据的方法
  const increment = ()=>{
    count.value++
  }

  const decrement = ()=>{
    count.value--
  }
  
  return { count, doubleCount, increment, decrement, num1, num2 }
}, {
  // @ts-ignore
  // unistorage: true, // 开启后对 state 的数据读写都将持久化
   unistorage: {
    key: 'cp-patient',
    paths: ['count', 'num2']
  }
})